package com.wyj.user.config;

import feign.Logger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.loadbalancer.core.RandomLoadBalancer;
import org.springframework.cloud.loadbalancer.core.ReactorLoadBalancer;
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

@Configuration
@Slf4j
public class FeignConfig {

    /**
     * TODO: 开启feign日志功能（需要配合系统日志的级别debug）
     *
     * @author wuyijie
     * @date 2022/2/10 6:53 PM
     * @return feign.Logger.Level
     */
    @Bean
    Logger.Level feignLoggerLevel(){
        return Logger.Level.BASIC;
    }

    /**
     * TODO: 采用随机算法
     *
     * @author wuyijie
     * @date 2022/2/12 12:03 PM
     * @param environment environment
     * @param loadBalancerClientFactory loadBalancerClientFactory
     * @return org.springframework.cloud.loadbalancer.core.ReactorLoadBalancer<org.springframework.cloud.client.ServiceInstance>
     */
    // @Bean
    // ReactorLoadBalancer<ServiceInstance> randomLoadBalancer(Environment environment,
    //                                                         LoadBalancerClientFactory loadBalancerClientFactory) {
    //     String name = environment.getProperty(LoadBalancerClientFactory.PROPERTY_NAME);
    //     return new RandomLoadBalancer(loadBalancerClientFactory
    //             .getLazyProvider(name, ServiceInstanceListSupplier.class),
    //             name);
    // }
}
